import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { WidgetConfig } from './widget-default-setting';

@Injectable({
  providedIn: 'root'
})
export class WidgetSharedService {
  private widgetConfigSource = new BehaviorSubject<WidgetConfig | null>(null);
  private widgetSource = new BehaviorSubject<WidgetConfig | null>(null);
  private widgetList = new BehaviorSubject<WidgetConfig[] | null>([]);
  updateWidget = this.widgetConfigSource.asObservable();
  initWidget = this.widgetSource.asObservable();

  constructor() {}

  initialWidget(widget: WidgetConfig): void {
    this.widgetSource.next(widget);
  }

  widgetConfigChange(widget: WidgetConfig): void {
    this.widgetConfigSource.next(widget);
  }

  setWidgetList(widgetList: WidgetConfig[]): void {
    this.widgetList.next(widgetList);
  }

  getWidgetList(): Observable<WidgetConfig[] | null> {
    return this.widgetList.asObservable();
  }
}
